package utfpr.gang5.hermes.controledepresenca.services.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;

import utfpr.gang5.hermes.controledepresenca.dao.CrudException;
import utfpr.gang5.hermes.controledepresenca.dao.GenericCrud;
import utfpr.gang5.hermes.controledepresenca.pojo.Professor;
import utfpr.gang5.hermes.controledepresenca.services.ProfessorService;
import utfpr.gang5.hermes.controledepresenca.util.HibernateUtil;

public class HibernateProfessorServiceImpl extends GenericCrud<Professor> implements
		ProfessorService {

	public HibernateProfessorServiceImpl() {
	}

	@Override
	public Professor carregar(Long id) throws CrudException {
		return carregar(Professor.class, id);
	}

	@Override
	public List<Professor> carregarTodos() throws CrudException {
		return carregarTodos(Professor.class);
	}

	@Override
	public Professor buscarPorUsername(String username) throws CrudException {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Criteria c1 = session.createCriteria(Professor.class);
		c1.add(Restrictions.eq("username", username));
		
		Object result = c1.uniqueResult();

		return (Professor) result;
	}


}
